<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/mb/jsp/common.jsp" %>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>活跃礼单</title>
</head>
<body ontouchstart="">
<div class="detailTop pf w100 of">
    <div class="w100 of tc cf f18">
        <span class="pa" style="left: 2px;" onclick="javascript:history.back();"><img src="mb/images/top_back_white.png" style="margin-top: 4px;height: 40px;width: 40px;"/></span>
      活跃礼单
     </div>
</div>
<div class="container db jz" style="padding-bottom: 0;padding-top: 46px;">

        <div id="resText"></div><!--resText-->
        <div id="loading" class="w100">
            <img src="mb/images/loading.gif" alt="正在加载" class="db jz hauto" style="width: 15px;">
            <div class="w100 tc f10 c9">正在加载</div>
        </div>
        
        <div  id="container" class="w100">
        
        </div>
</div>

<script type="text/javascript">
  	$(document).ready(function(){
		getData();
	});

    
    //加载新数据
    function getData() {
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m: 1665}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
                showProgressDg();
            },
            success: function (data) {
               if (data.state == 1) {
                  showData(data.list);
                } else {
                    // 其他错误弹出提示
                    showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
    }
    
    
    
     function showData(list)
    {   
        console.log(list);
    	var htmlStr="";
    	 var btnDiv = "";
         var imgBlock = "";
         var faHuoBlock ="";
         var timeBlock ="";
    	$.each(list, function(index, obj) 
    	{
    		var tmpimg=obj.prestigeimage.split(";")[0];
    		var prestigeid = obj.prestigeid;
			var orderid = obj.orderid;
    		if(obj.prestigeintro == ""||obj.prestigeintro == undefined||obj.prestigeintro == null){
    		   obj.prestigeintro = "暂无";
    		};
    		
    		
    		
    		  //新增的iscanback属性
    		var iscanback = obj.iscanback;
    		var canbackLable = "";
    		var canbackBtn = "";
    		
    		if(iscanback == 0){
    		   canbackLable = '(不支持回购)';
    		   canbackBtn ='<button class="tc cf f15 modifyBtn fr" style="width:49%;background:#ccc" disabled="disabled">不支持回购</button>';
    		}
    		else if(iscanback == 1){
    		  canbackLable = '回购价：'+obj.callbackprice;
    		  canbackBtn ='<button class="tc cf f15 modifyBtn fr" style="width:49%;" onclick="buyBack('+ orderid +')">回购</button>';
    		}
    		
           
            if(obj.state== -1){
               btnDiv =
             			'<div style="width:96%;border-top:1px solid #ececec;padding:7px 0;" class="jz mgt10 clearfix of">'+
				           '<button class="tc cf f15 modifyBtn fl" style="width:49%;" onclick="sendGoods('+ orderid +')">发货</button>'+
				           	canbackBtn+
				        '</div>';
				imgBlock =
							'<div class="fl mgt10" style="margin-left:2%;">'+
				                  '<img src="'+getBaseImgUrl(tmpimg)+'" class="kmImg mgt10">'+
				             '</div>';
				 faHuoBlock="";
				 timeBlock= '<p class="c9 f12 lh18">领取时间：'+obj.ctime+'</p>';            
            } 
            else if(obj.state== 0){
                btnDiv = "";
               
                imgBlock =
							'<div class="fl mgt10" style="margin-left:2%;">'+
				                  '<img src="'+getBaseImgUrl(tmpimg)+'" class="kmImg mgt10">'+
				                  '<div class="w100 tc cf f13 clearfix of bcgreen lh2">已发货</div>'+
				             '</div>';
		        faHuoBlock =  '<p class="c9 f12 lh18" style="margin-top: 3px;">快递单号：'+obj.courier_sn+'</p>'+
                       		  '<p class="c9 f12 lh18" style="margin-top: 3px;">发货信息：'+obj.address+'</p>';
				timeBlock= '<p class="c9 f12 lh18">发货时间：'+obj.couriertime+'</p>';             
            }
            else if(obj.state== 1){
                btnDiv = "";
                imgBlock =
							'<div class="fl mgt10" style="margin-left:2%;">'+
				                  '<img src="'+getBaseImgUrl(tmpimg)+'" class="kmImg mgt10">'+
				                  '<div class="w100 tc cf f13 clearfix of bcgreen lh2">已回购</div>'+
				             '</div>';
				faHuoBlock="";
				timeBlock= '<p class="c9 f12 lh18">回购时间：'+obj.couriertime+'</p>';               
            }
            
            
          
            
            
    		htmlStr+=
	    		   	'<section id="proSection'+ orderid +'" class="proSection pr w100 bcf">'+
					   '<a href="mb/jsp/shengWangOrderDetail.jsp?orderid=' + orderid + '" class="w100 db">'+
				            '<article class="of clearfix jz">'+
				                imgBlock +
				                '<div class="fr dib pdb10" style="margin-right:2%;margin-left:2%;width:68%;">'+
				                    '<h5 class="c3 f13 mgt10 lh2">'+obj.prestigename+'</h5>'+
				                    '<p class="c9 f12 lh2">'+canbackLable+'&nbsp;&nbsp;&nbsp;&nbsp;市场价:<span class="lineThroughSpan">'+obj.oldprice+'</span></p>'+
				                    timeBlock +
				                    '<p class="c9 f12 lh18" style="margin-top: 3px;">简介：'+obj.prestigeintro+'</p>'+
				                    faHuoBlock +
				                '</div>'+
				            '</article>'+
				        '</a>'+
				          btnDiv +
					'</section>';
					
    	});
    	
    	 $("#container").html(htmlStr);
    }
    
    // 回购
	function buyBack(orderid) {
	    layer.confirm('确认回购?(将会按回购价回购到余额)', function(){ 
			buyBackDo(orderid);
			layer.closeAll();
		});
    } 
    
    // 回购
	function buyBackDo(orderidVal) {
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m: 1667,orderid:orderidVal}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
				showProgressDg();
            },
            success: function (data) {
               if (data.state == 1) {
                  // 成功弹出提示
                  showToast(data.info);
                  setTimeout('window.location.reload()', 1600); 
                } else {
                    // 其他错误弹出提示
                   showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
    } 
    
     // 发货
	function sendGoods(orderid) {
	
		layer.confirm('确认发货?(将会把实物发货给您)', function(){ 
			 window.location.href="mb/jsp/myAddressOrder.jsp?orderid=" + orderid +"_shengwang";
			 layer.closeAll();
		});
	
      /*   $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m: 1666,orderid:orderid}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
				showProgressDg();
            },
            success: function (data) {
               if (data.state == 1) {
                  // 成功弹出提示
                  showToast(data.info);
                  setTimeout('window.location.reload()', 1600); 
                } else {
                    // 其他错误弹出提示
                   showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        }); */
    } 
    
    
  
</script>
</body>
</html>
